/**
 * Created by 落叶的思恋 on 2016/12/3.
 */

$(document).ready(function() {
 var ss=0;
    /**
     *
     * 顶部的导航栏
    **/
    $.event.special.swipe.horizontalDistanceThreshold = 10;
    $.Velocity.RegisterUI('lixin.slideLeftIn',{
        defaultDuration:1000,
        calls:[
            [{opacity:[1,0],translateX:[0,200]}]
        ]
    });
    $.Velocity.RegisterUI('lixin.slideRightIn',{
        defaultDuration:1000,
        calls:[
            [{opacity:[1,0],translateX:[0,-200]}]
        ]
    });
    var topul = $('.topul>li>a');
    $(topul[0]).addClass("select");
    var centerul = $('.outer>ul');
    topul.click(function () {
        ss=0;
        var i = 0;
        for (i = 0; i < topul.length; i++) {
            $(topul[i]).removeClass("select");
            $(this).addClass("select");
        }
        for (var i = 0; i < topul.length; i++) {
            if ($(topul[i]).hasClass("select")) {
                changeGroupType(i + 1)
                $(centerul[i]).css("display", "block");


            }
        }
    })

    /**
     * 头部向左活动
     */
    topul.on('swipeleft',function (exent) {
        ss=0;
        var moveleft = $(topul).parent().parent().parent().width() * 0.25;
        var leftparent = $(topul).parent().parent().position().left;
        if (leftparent > (-(moveleft * 3))) {
            $(topul).parent().parent().animate({left: -3 * moveleft + 'px'}, 500)
        }

    });
    /**
     * 导航栏向右活动
     */
    topul.on('swiperight',function () {
        ss=0;
        var moveleft = $(topul).parent().parent().parent().width() * 0.25;
        var leftparent = $(topul).parent().parent().position().left;
        if (leftparent >= (-(moveleft * 3))) {
            $(topul).parent().parent().animate({left: 0 + 'px'}, 500)

        }

    });
    /**
     * 列表部分向左滑动
     * */

        $('.outer>ul').on('swipeleft',function () {
            ss=0;
        for (var i = 0; i < topul.length; i++) {
            if ($(topul[i]).hasClass("select") && i != 6) {
                var i = 0;
                for (i = 0; i < topul.length; i++) {
                    $(topul[i]).css('display', 'black')
                    if ($(topul[i]).hasClass("select")) {
                        $(topul[i]).removeClass("select");
                        $(topul[i + 1]).addClass("select");
                        changeGroupType(i + 2);
                        var imgout = [
                            {
                                elements: $(this),
                                properties:'lixin.slideLeftIn',
                                options: {sequenceQueue: false}
                            }]
                        $.Velocity.RunSequence(imgout);
                        $('.outer>ul').css({left:0+'px'});
                        $('.outer').css({left:0+'px'});
                        break;
                    }

                }

                for (i = 0; i < topul.length; i++) {
                    if ($(topul[i]).hasClass("select")) {
                        var moveleft = $(topul[i]).parent().parent().parent().width() * 0.25;
                        var leftparent = $(topul[i]).parent().parent().position().left;
                        if (leftparent > (-(moveleft * 3))+5) {
                            $(topul[i]).parent().parent().animate({left: leftparent - moveleft + 'px'})
                        }
                    }
                }
            }
        }

    });

    /**
     * 列表部分向右滑动
     * */

    $('.outer>ul').on('swiperight',function () {
        ss=0;
        for (var i = 0; i < topul.length; i++) {
            if ($(topul[i]).hasClass("select") && i != 0) {
                for (i = 0; i < topul.length; i++) {
                    if ($(topul[i]).hasClass("select")) {
                        var moveleft = $(topul[i]).parent().parent().parent().width() * 0.25;
                        var leftparent = $(topul[i]).parent().parent().position().left;
                        if (leftparent+10 < 0) {
                            $(topul[i]).parent().parent().animate({left: leftparent + moveleft + 'px'})
                        }
                    }
                }
                var i = 0;
                for (i = 0; i < topul.length; i++) {
                    $(topul[i]).css('display', 'black')
                    if ($(topul[i]).hasClass("select")) {
                        $(topul[i]).removeClass("select");
                        $(topul[i - 1]).addClass("select");
                        changeGroupType(i);
                        var imgout = [
                            {
                                elements: $(this),
                                properties: 'lixin.slideRightIn',
                                options: {sequenceQueue: false}
                            }]
                        $.Velocity.RunSequence(imgout);
                        break;
                        $('.outer>ul').css({left:0+'px'});
                        $('.outer').css({left:0+'px'});
                    }
                }

            }
        }

    });



});